package cn.iocoder.yudao.module.signature.dal.mysql.device;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.signature.controller.admin.device.vo.AppleDevicePageReqVO;
import cn.iocoder.yudao.module.signature.dal.dataobject.device.AppleDeviceDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 苹果设备信息 Mapper
 *
 * @author base
 */
@Mapper
public interface AppleDeviceMapper extends BaseMapperX<AppleDeviceDO> {

    default PageResult<AppleDeviceDO> selectPage(AppleDevicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AppleDeviceDO>()
                .eqIfPresent(AppleDeviceDO::getUdid, reqVO.getUdid())
                .eqIfPresent(AppleDeviceDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(AppleDeviceDO::getCerId, reqVO.getCerId())
                .eqIfPresent(AppleDeviceDO::getCerNumber, reqVO.getCerNumber())
                .eqIfPresent(AppleDeviceDO::getAppAccountId, reqVO.getAppAccountId())
                .eqIfPresent(AppleDeviceDO::getAccountType, reqVO.getAccountType())
                .eqIfPresent(AppleDeviceDO::getWarrantyType, reqVO.getWarrantyType())
                .eqIfPresent(AppleDeviceDO::getClassType, reqVO.getClassType())
                .eqIfPresent(AppleDeviceDO::getOrderVersion, reqVO.getOrderVersion())
                .likeIfPresent(AppleDeviceDO::getCerName, reqVO.getCerName())
                .likeIfPresent(AppleDeviceDO::getUserName, reqVO.getUserName())
                .betweenIfPresent(AppleDeviceDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AppleDeviceDO::getId));
    }

    /**
     * 查询指定 udid 的苹果设备信息
     * @param udid
     * @param userId
     * @return
     */
    default AppleDeviceDO selectByUdidAndUserId(String udid, Long userId) {
        return selectOne(new LambdaQueryWrapperX<AppleDeviceDO>()
                .eq(AppleDeviceDO::getUdid, udid)
                .eq(AppleDeviceDO::getUserId, userId)
                .eq(AppleDeviceDO::getDropFlag,false)
                .orderByDesc(BaseDO::getUpdateTime)
                .last("LIMIT 1")
        );
    }

    default AppleDeviceDO selectByUdid(String udid) {
        return selectOne(new LambdaQueryWrapperX<AppleDeviceDO>()
                .eq(AppleDeviceDO::getUdid, udid)
                .eq(AppleDeviceDO::getDropFlag,false)
                .orderByDesc(BaseDO::getUpdateTime)
                .last("LIMIT 1")
        );
    }

}